import java.util.HashMap;
import java.util.Map;

/**
 * @author tmh
 * @date 2024/9/20 15:44
 * @description
 */
public class T1两数之和 {
    public int[] twoSum(int[] nums, int target) {
        //1.使用HashMap来降低时间复杂度
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{i, map.get(target - nums[i])};
            }else {
                map.put(nums[i],i);
            }
        }
        return null;
    }
}
